package com.halcyon.ui.activity;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.halcyon.R;

public abstract class BaseActivity extends AppCompatActivity implements View.OnClickListener{
    protected Toolbar mToolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView(savedInstanceState);
        mToolbar = getViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        findViews();
        setListeners();
        initData();
    }

    /**
     * 初始化布局
     *
     * @param savedInstanceState
     */
    protected abstract void initView(Bundle savedInstanceState);

    protected void findViews(){

    }

    /**
     * 设置监听事件
     */
    protected void setListeners() {

    }

    /**
     * 初始化数据
     */
    protected void initData() {

    }

    /**
     * 刷新数据
     */
    public void refreshData() {

    }

    @Override
    public void onClick(View v) {

    }

    /**
     * 查找View
     *
     * @param id   控件的id
     * @param <VT> View类型
     * @return
     */
    @SuppressWarnings("unchecked")
    protected <VT extends View> VT getViewById(@IdRes int id) {
        return (VT) this.findViewById(id);
    }

}